package com.qianfeng.exam.controller;

import com.github.pagehelper.PageInfo;
import com.qianfeng.exam.dto.BooksDto;
import com.qianfeng.exam.dto.R;
import com.qianfeng.exam.service.IBookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/book")
public class BooksController{
    @Autowired
    private IBookService bookService;

    @PostMapping("/newbook")
    public R addBook(@RequestBody BooksDto books){
         bookService.addBook(books);
         return R.setOk(books,"添加小说成功");
    }

    @GetMapping("/books/{name}/{pageNum}/{pageSize}")
    public R getAllBooksByPage(@PathVariable String name,@PathVariable @RequestParam(defaultValue = "1")int pageNum,@PathVariable @RequestParam(defaultValue = "10")int pageSize){
        System.err.println("=========================="+"name = " + name + ", pageNum = " + pageNum + ", pageSize = " + pageSize);
        PageInfo<BooksDto> result = bookService.findAllDevice(pageNum,pageSize,name);
         return R.setOk(result,result!=null?"查询成功":"没有查询到数据");
    }


}
